package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.MerchantConfig;
import io.geekidea.springbootplus.system.param.MerchantConfigStatusParam;
import io.geekidea.springbootplus.system.service.MerchantConfigService;
import io.geekidea.springbootplus.system.vo.MerchantConfigQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/shopConfig")
@Module("system")
@Api(value = "店铺设置API", tags = {"店铺设置"})
public class MerchantConfigController extends BaseController {
    @Resource
    private MerchantConfigService sysMerchantConfigService;


    @PostMapping("/add")
    @OperationLog(name = "添加店铺信息", type = OperationLogType.ADD)
    @ApiOperation(value = "添加店铺信息", response = MerchantConfig.class)
    public ApiResult<String> addShopConfig(@RequestBody MerchantConfigQueryVo sysMerchantConfig)throws Exception {
        boolean result = sysMerchantConfigService.addConfig(sysMerchantConfig);
        if (result){
            return ApiResult.ok("添加店铺信息成功！");
        }else {
            return ApiResult.ok("添加店铺信息失败！");
        }
    }

    @PostMapping("/delete/{id}")
    @OperationLog(name = "店铺信息", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除店铺信息", response = MerchantConfig.class)
    public ApiResult<String> deleteShopConfig (@PathVariable("id") Integer id )throws Exception{
        boolean result = sysMerchantConfigService.deleteConfig(id);
        if (result){
            return ApiResult.ok("删除店铺信息成功！");
        }else {
            return ApiResult.ok("删除店铺信息失败！");
        }
    }

    @PostMapping("/update")
    @OperationLog(name = "修改信息", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改信息", response = MerchantConfig.class)
    public ApiResult<String> updateConfig(@RequestBody MerchantConfigQueryVo merchantConfigQueryVo)throws Exception {
        boolean result = sysMerchantConfigService.updateConfig(merchantConfigQueryVo);
        if (result){
            return ApiResult.ok("修改信息成功！");
        }else {
            return ApiResult.ok("修改信息失败！");
        }
    }

    @PostMapping("/updateStatus")
    @OperationLog(name = "营业状态", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改营业状态", response = MerchantConfig.class)
    public ApiResult<String> updateStatusConfig(@RequestBody MerchantConfigStatusParam sysMerchantConfig)throws Exception {
        boolean result = sysMerchantConfigService.updateStatus(sysMerchantConfig);
        if (result){
            return ApiResult.ok("修改营业状态信息成功！");
        }else {
            return ApiResult.ok("修改营业状态信息失败！");
        }
    }

    @PostMapping("/list")
    @OperationLog(name = "店铺信息", type = OperationLogType.INFO)
    @ApiOperation(value = "所有店铺信息", response = MerchantConfig.class)
    public ApiResult< List<MerchantConfigQueryVo>> selectConfig()throws Exception {
        List<MerchantConfigQueryVo> config = sysMerchantConfigService.findConfig();
        return ApiResult.ok(config);
    }



    @PostMapping("/selectOne/{id}")
    @OperationLog(name = "店铺信息", type = OperationLogType.INFO)
    @ApiOperation(value = "单个店铺信息", response = MerchantConfig.class)
    public ApiResult<MerchantConfigQueryVo> selectConfigById(@PathVariable("id") Integer id)throws Exception {
        MerchantConfigQueryVo merchantConfigQueryVo = sysMerchantConfigService.finConfigById(id);
        return ApiResult.ok(merchantConfigQueryVo,"查询单个店铺信息成功！");
    }

}
